
package com.baidu.zhang.database;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Interface of data access to SqliteDatabase.
 * 
 */
public interface IDataAccess {
	
	/**
	 * Delete data record with specified id.
	 * @param db
	 *            Exposes methods to manage a SQLite database.
	 * @param id
	 *            The identifier of object to be deleted.
	 * @return Return the number of rows of execution results, -1 represents an exception.
	 */
	int delete(SQLiteDatabase db, String id);

	/**
	 * Delete data records with specified delete conditions.
	 * @param db
	 *            Exposes methods to manage a SQLite database.
	 * @param where
	 *            delete conditions for objects to be deleted.
	 * @param whereArgs
	 *            Params of delete condition.
	 * @return Return the number of rows of execution results, -1 represents an exception.
	 */
	int delete(SQLiteDatabase db, String where, String[] whereArgs);

	/**
	 * Insert a record in a specified table.
	 * @param db
	 *            Exposes methods to manage a SQLite database.
	 * @param initialValues
	 *            The column/value data block.
	 * @return Return id of new record, 0 represents no execution,-1 represents an exception.
	 */
	long insert(SQLiteDatabase db, ContentValues initialValues);

	/**
	 * Query data record by specified id.
	 * @param db
	 *            Exposes methods to manage a SQLite database.
	 * @param columns
	 *            Query column collection,null is equal to "*".
	 * @param id
	 *            Value of id.
	 * @return Cursor of query results.
	 */
	Cursor query(SQLiteDatabase db, String[] columns, String id);

	/**
	 * Query sorted data record(s) by specified condition and sort mode.
	 * @param db
	 *            Exposes methods to manage a SQLite database.
	 * @param columns
	 *            Query column collection,null is equal to "*".
	 * @param where
	 *            Query condition.
	 * @param whereArgs
	 *            Params of query condition.
	 * @param sortOrder
	 *            Sort mode of query results.
	 * @return Cursor of query results.
	 */
	Cursor query(SQLiteDatabase db, String[] columns, String where, String[] whereArgs,
			String sortOrder);

	/**
	 * Query paging,sorted data record(s) by specified condition and sort mode.
	 * 
	 * @param db
	 *            Exposes methods to manage a SQLite database.
	 * @param columns
	 *            Query column collection,null is equal to "*".
	 * @param where
	 *            Query condition.
	 * @param whereArgs
	 *            Params of query condition.
	 * @param sortOrder
	 *            Sort mode of query results.
	 * @param startIndex
	 *            Start index of paging data.
	 * @param maxCount
	 *            Max count of pagin data.
	 * @return Cursor of query results.
	 */
	Cursor query(SQLiteDatabase db, String[] columns, String where, String[] whereArgs,
			String sortOrder, int startIndex, int maxCount);

	/**
	 * Update data record by specified id.
	 * @param db
	 *            Exposes methods to manage a SQLite database.
	 * @param id
	 *            The identifier of object to be updated.
	 * @return Return the number of rows of execution results, -1 represents an exception.
	 */
	int update(SQLiteDatabase db, ContentValues values, String id);

	/**
	 * Update data records with specified update conditions.
	 * @param db
	 *            Exposes methods to manage a SQLite database.
	 * @param where
	 *            Conditions for objects to be updated.
	 * @param whereArgs
	 *            Params of conditions.
	 * @return Return the number of rows of execution results, -1 represents an exception.
	 */
	int update(SQLiteDatabase db, String where, String[] whereArgs, ContentValues values);
}
